package com.lovo.roomProject.room.service.impl;

import com.lovo.roomProject.pojo.CutPageBean;
import com.lovo.roomProject.pojo.RoomDO;
import com.lovo.roomProject.room.dao.RoomDAO;
import com.lovo.roomProject.room.dao.impl.RoomDAOImpl;
import com.lovo.roomProject.room.service.RoomService;

import javax.swing.*;
import java.util.List;

public class RoomServiceImpl implements RoomService {
    private RoomDAO roomDAO=new RoomDAOImpl();
    @Override
    public List listRoom() {
        return roomDAO.listRoom();
    }

    @Override
    public List listRoom(int id) {
        return roomDAO.listRoom(id);
    }

    @Override
    public List listRoom(String type) {
        return roomDAO.listRoom(type);
    }

    @Override
    public void insert(RoomDO roomDO) {
        roomDAO.insert(roomDO);
    }

    @Override
    public CutPageBean listRoomPage(int current,String addr,String status,String can,String type) {
        return roomDAO.listRoomPage(current,addr,status,can,type);
    }

    @Override
    public RoomDO getRoomID(int id) {
        return roomDAO.getRoomID(id);
    }

    @Override
    public void delete(int id) throws Exception{
        RoomDO roomDO=roomDAO.getRoomID(id);
        if (roomDO.getInCount()==0){
            roomDAO.delete(id);
        }else{
            throw new Exception("房间有人住");
        }

    }
}
